package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.*;
import com.spzx.product.api.domain.vo.SkuLockVo;
import com.spzx.product.api.domain.vo.SkuStockVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author Haoran Sun
 * @since 2024/07/23
 */

@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    @Override
    public RemoteProductService create(Throwable cause) {

        return new RemoteProductService(){

            @Override
            public R<List<ProductSku>> getTopSale(String source) {
                return R.fail("获取一级分类列表失败" + cause.getMessage());
            }

            @Override
            public R<TableDataInfo> skuList(Integer pageNum, Integer pageSize, SkuQuery skuQuery, String source) {
                return R.fail("分页查询sku列表失败" + cause.getMessage());
            }

            @Override
            public R<ProductSku> getProductSku(Long skuId, String source) {
                return R.fail("获取sku信息失败" + cause.getMessage());
            }

            @Override
            public R<Product> getProduct(Long id, String source) {
                return R.fail("获取商品信息失败" + cause.getMessage());
            }

            @Override
            public R<SkuPrice> getSkuPrice(Long skuId, String source) {
                return R.fail("获取sku价格失败" + cause.getMessage());
            }

            @Override
            public R<ProductDetails> getProductDetails(Long id, String source) {
                return R.fail("获取商品详情失败" + cause.getMessage());
            }

            @Override
            public R<Map<String, Long>> getSkuSpecValue(Long id, String source) {
                return R.fail("获取sku规格值失败" + cause.getMessage());
            }

            @Override
            public R<SkuStockVo> getSkuStock(Long skuId, String source) {
                return R.fail("获取sku库存失败" + cause.getMessage());
            }

            @Override
            public R<List<SkuPrice>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("根据skuId列表获取sku价格信息失败" + cause.getMessage());
            }

            @Override
            public R<String> checkAndLock(String orderNo, List<SkuLockVo> skuLockVoList, String source) {
                return R.fail("检查与锁定库存失败" + cause.getMessage());
            }
        };
    }
}
